package com.tnl.app.controller;

import com.biz.hunter.db.entity.*;
import com.tnl.app.dao.*;
import com.tnl.app.entity.OrderDesc;
import com.tnl.app.entity.Order;
import com.tnl.base.web.JsonController;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/orderResume")
public class OrderResumeController extends JsonController {

    @Autowired
    private OrderDAO orderDAO;

    @Autowired
    private OrderResumeDAO resumeDAO;

    @Autowired
    private OrderSalaryDAO salaryDAO;

    @Autowired
    private OrderPlanDAO planDAO;

    @Autowired
    private OrderInterviewDAO interviewDAO;

    @Autowired
    private OrderLeaveDAO leaveDAO;

    @Autowired
    private OrderDescDAO descDAO;

    @RequestMapping(value = "hasSubmitInfo")
    public void getOrderResume(HttpServletResponse response, HttpServletRequest request, Long orderId){
        Order order = orderDAO.getById(orderId.intValue());

        boolean flag = checkCustomerSupplyInfo(order);
        if(flag){
            this.successJson(1, "订单信息完善", response);
            return;
        }
        this.successJson(0, "订单信息完善", response);
    }

    private boolean checkCustomerSupplyInfo(Order order) {
        OrderDesc desc = descDAO.getById(order.getOrdescId());
        Long orderId = order.getId();
        if (desc.getTag().indexOf("简历修改") != -1){
            OrderResume resume = resumeDAO.getByOrderId(orderId);
            return resume != null && StringUtils.isNotEmpty(resume.getFile());
        }
        if (desc.getTag().indexOf("面试辅导") != -1){
            OrderInterview interview = interviewDAO.getInterviewByOrderId(orderId);
            return interview != null && StringUtils.isNotEmpty(interview.getFile());
        }

        if (desc.getTag().indexOf("薪酬分析") != -1){
            OrderSalary salary = salaryDAO.getByOrderId(orderId);
            return salary != null;
        }

        if (desc.getTag().indexOf("职业规划") != -1){
            OrderPlan orderPlan = planDAO.getPlanByOrderId(orderId);
            return orderPlan != null;
        }


        if (desc.getTag().indexOf("离职咨询") != -1){
            OrderLeave orderLeave = leaveDAO.getLeaveByOrderId(orderId);
            return orderLeave != null;
        }

        return false;
    }

}
